home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
tools.lha
/
tools
/
error.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
1KB
|
68 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ Error function. fmt is a printf-style format string.
/ The formatted message is written to the error
/ stream and then the function calls exit(1).
include <stream.h>
include <stdarg.h>
xtern void exit(int);
oid error(const char *fmt ...)
va_list ap;
va_start(ap, fmt);
char ch;
// loop across format string
while (ch = *fmt++)
// output normal chars
if (ch != '%')
cerr.put(ch);
else
// found % sequence
switch (ch = *fmt++)
{
// %% becomes a single %
case '%':
cerr.put('%');
break;
// output string
case 's':
{
char *s = va_arg(ap, char*);
cerr << s;
}
break;
// output decimal integer
case 'd':
{
int s = va_arg(ap, int);
cerr << s;
}
break;
// output character
case 'c':
{
int s = va_arg(ap, int);
cerr.put(s);
}
break;
default:
cerr << "\nunknown % sequence: %" <<
chr(ch) << "\n";
break;
}
// all done
va_end(ap);
exit(1);